<template>
  <div>
    <div class="pcMenus" v-if="isPC">
      <div class="common-menu-list">
        <div
          class="menu-item"
          :class="{ selected: selected === idx }"
          v-for="(item, idx) in tabList"
          @click="clickTab(idx)"
          :key="idx"
        >
          {{ item }}
        </div>
      </div>
    </div>
    <div class="mobile_menus" v-else>
      <div class="common-menu-list">
        <div
          class="menu-item"
          :class="{ selected: selected === idx }"
          v-for="(item, idx) in tabList"
          @click="clickTab(idx)"
          :key="idx"
        >
          {{ item }}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    tabList: {
      type: Array,
      default: null,
    },
  },
  data: () => ({
    selected: 0,
  }),
  computed: {
    isPC() {
      return this.$store.state.clientWidth > 960 ? true : false;
    },
  },
  methods: {
    clickTab(idx) {
      this.selected = idx;
      this.$emit("onClick", idx);
    },
  },
};
</script>
<style  lang="scss" scoped>
.pcMenus {
  text-align: center;
  .common-menu-list {
    border-radius: 12px;
    font-size: 16px;
    height: 44px;
    text-align: center;
    position: relative;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    overflow: auto;
    background-color: #f7f7f7;
    -webkit-box-shadow: 0 6px 12px 0 rgb(0 0 0 / 6%);
    box-shadow: 0 6px 12px 0 rgb(0 0 0 / 6%);
    -webkit-overflow-scrolling: touch;
    .menu-item {
      position: relative;
      color: #694f4e;
      -webkit-transition: color 0.2s ease;
      transition: color 0.2s ease;
      white-space: nowrap;
      min-width: 100px;
      height: 100%;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      justify-content: center;
      padding: 0 20px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      border-radius: 12px;
      font-weight: 700;
    }
    .selected {
      color: #431216;
      background: #fad551;
    }
  }
}
.mobile_menus {
  text-align: center;
  .common-menu-list {
    border-radius: 12px;
    text-align: center;
    position: relative;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    overflow: auto;
    background-color: #f7f7f7;
    -webkit-box-shadow: 0 6px 12px 0 rgb(0 0 0 / 6%);
    box-shadow: 0 6px 12px 0 rgb(0 0 0 / 6%);
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
    height: 40px;
    width: 100%;
    .menu-item {
      position: relative;
      color: #694f4e;
      -webkit-transition: color 0.2s ease;
      transition: color 0.2s ease;
      white-space: nowrap;
      min-width: 100px;
      height: 100%;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      justify-content: center;
      padding: 0 20px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      border-radius: 12px;
      font-weight: 700;
      min-width: unset;
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
      padding: 0 14px;
    }
    .selected {
      color: #431216;
      background: #fad551;
    }
  }
}
</style>